<?php
namespace Admin\Controller;
use Think\Controller;
class WxauthoriseController extends Controller {
   public function _initialize()  
    {  
		header("Content-Type: text/html; charset=utf-8");

    	if(!session('user')){
    		$message=D('User')->loginout(2);
    		$this->success($message,U('index/index'));die;
    	}
    } 
	//产品列表首页
	public function manage_diqu_chanpin(){
		dump(12);die;
		$bm_goods_gx = M('goods_gx'); 		//关系表 主要用查询ID
		$bm_goods_foundation = M('goods_foundation');		//基础信息表
		$Gx = $bm_goods_gx->field('id')->where('shifou = 2')->select();

		/*****************联表查询**********************************/

		if($_GET['search']){
			$search=$_GET['search'];
			$where['name']=array('LIKE',"%".$search."%");
			if(!$_GET['p'])$_get['p']=1;
			$data = M('user');
			$count = $bm_goods_gx
				 ->alias('a')
				 ->join('bm_goods_foundation b ON a.id=b.gx_id','LEFT')
				 ->field('b.name,b.dtypename,b.qudaoname,a.id,a.timeda,b.u_id,a.j_id')
				 ->group('a.id')
				 ->where("a.shifou = 2 and b.u_id=".session('user.u_id'))
				 ->where($where)
				 ->count();// 查询满足要求的总记录数
			$Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show       = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list=$bm_goods_gx
				 ->alias('a')
				 ->join('bm_goods_foundation b ON a.id=b.gx_id','LEFT')
				 ->field('b.name,b.dtypename,b.qudaoname,a.id,a.timeda,b.u_id,a.j_id')
				 ->where("a.shifou = 2 and b.u_id=".session('user.u_id'))
				 ->where($where)
				 ->group('a.id')
				 ->limit($Page->firstRow.','.$Page->listRows)
				 ->select();
		}
		else{
			if(!$_GET['p'])$_get['p']=1;
			$count = $bm_goods_gx
				 ->alias('a')
				 ->join('bm_goods_foundation b ON a.id=b.gx_id','LEFT')
				 ->field('b.name,b.dtypename,b.qudaoname,a.id,a.timeda,b.u_id,a.j_id')
				 ->where("a.shifou = 2 and b.u_id=".session('user.u_id'))
				 //->group('a.id')
				// ->where("b.dtypename=".$_GET['search'])
				 ->count();// 查询满足要求的总记录数
			$Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show       = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list=$bm_goods_gx
				 ->alias('a')
				 ->join('bm_goods_foundation b ON a.id=b.gx_id','LEFT')
				 ->field('b.name,b.dtypename,b.qudaoname,a.id,a.timeda,b.u_id,a.j_id')
				 ->where("a.shifou = 2 and b.u_id=".session('user.u_id'))
				 ->group('a.id')
				 ->limit($Page->firstRow.','.$Page->listRows)
				 //->fetchSql(true)
				 ->select();
				// dump($list);
		}
			$this->assign('count',$count);
			$this->assign('list',$list);// 赋值数据集
			$this->assign('page',$show);// 赋值分页输出


		/*****************联表查询**********************************/

		$this->display();
	}
	/**
	 * 删除产品
	 * @return [type] [description]
	 */
	public function manage_diqu_del(){
			$del=$_POST['id_arr'];
			foreach ($_POST['id_arr'] as $key => $value) {
				$del_arr=$value.$del_arr;
				if($_POST['id_arr'][$key+1]){
					$del_arr=','.$del_arr;
				}
			}
			
			$r1=M('goods_gx');
			$r2=M('goods_foundation');
			$r3=M('goods');
			$where['gx_id']=array("IN",$del_arr);
			$r1->startTrans();
			$r2->startTrans();
			$r3->startTrans();
			$res=$r1->delete($del_arr);
			$res2=$r2->where($where)->delete();
			$res3=$r3->where($where)->delete();
			if($res&&$res2&&$res3){
				$r1->commit();
				$r2->commit();
				$r3->commit();
				$this->success('删除成功',U('manage_diqu_chanpin'),1);
			}
			else{
				$r1->rollback();
				$r2->rollback();
				$r3->rollback();
				$this->error('删除失败',U('manage_diqu_chanpin'),1);
			}
	}
	//产品添加1页面
	public function add_chanpin(){
		$id = I('dID','');			//关系表ID
		$bm_goods = M('goods');			//商品表ID
		$bm_goods_foundation = M('goods_foundation');	//商品基础信息表
		$bm_biaoqian = M('biaoqian');						//标签表
		$bm_lx = M('lx');									//商品信息表
		if($id != ''){
			$arr['gx_id'] = $id;
			$goods = $bm_goods->where($arr)->select();
				for($i = 0; $i <count($goods);$i++){
					if($goods[$i]['cp_temp'] != ''){
					$count = chanfen($goods[$i]['cp_temp'],$goods[$i]['revenue'],$goods[$i]['jinjian'],$goods[$i]['lx'],$goods[$i]['assessment'],$goods[$i]['datami'],$goods[$i]['area'],$goods[$i]['especial']);
					$bqID = $goods[$i]['daleiid'];
					$goods[$i]['count']=$count;
					$Bqian = $bm_biaoqian->field('name')->where('id='.$bqID)->find();			//查询出标签名字大类
					$goods[$i]['name'] = $Bqian['name'];														//输出大类标签
					//查出小类标签
					$str1 = explode(',',$goods[$i]['cp_temp']);
					for($k = 0; $k <count($str1);$k++){
						
						$Bxqian = $bm_biaoqian->field('name')->where('id='.$str1[$k])->find();
						$goods[$i]['xiaolei'] .= $Bxqian['name'].',';//输出小类标签
					}
					
					$Lxi = $bm_lx->field('min_lx,max_lx,min_ed,max_ed')->where('g_id = '.$goods[$i]['id'])->select();
				    /********************** 逻辑替换，开始2018-06-29 19:10:18********************/

                      $goods[$i]['min_lx']=$my_temp['min_lx']=$Lxi[0]['min_lx'];
                      $goods[$i]['max_lx']=$my_temp['max_lx']=$Lxi[0]['max_lx'];
                      $goods[$i]['min_ed']=$my_temp['min_ed']=$Lxi[0]['min_ed'];
                      $goods[$i]['max_ed']=$my_temp['max_ed']=$Lxi[0]['max_ed'];  
                      foreach ($Lxi as $k => $v) {
                         if($Lxi[$k]['min_lx']<$my_temp['min_lx']){
                            $goods[$i]['min_lx']=$my_temp['min_lx']=$Lxi[$k]['min_lx'];
                         }
                         if($Lxi[$k]['max_lx']>$my_temp['max_lx']){
                            $goods[$i]['max_lx']=$my_temp['max_lx']=$Lxi[$k]['max_lx'];
                         }
                         if($Lxi[$k]['min_ed']<$my_temp['min_ed']){
                             $goods[$i]['min_ed']=$my_temp['min_ed']=$Lxi[$k]['min_ed'];
                         }
                         if($Lxi[$k]['max_ed']>$my_temp['max_ed']){
                            $goods[$i]['max_ed']=$my_temp['max_ed']=$Lxi[$k]['max_ed'];
                         }
                      }
				    /********************** 逻辑替换，结束2018-06-29 19:10:18********************/
				}	
			}
			//产品基础信息表
			$BMjc = $bm_goods_foundation->where('gx_id = '.$id)->select();
			$this->assign('BMjc',$BMjc);			//基础信息表渲染模板
			$this->assign('fid',$id);				//关联ID
			$this->assign('info',$goods);			//核心信息标签渲染模板
	
		
		}
/***********************新增渲染数据（征信，广告，关联产品）*******************************/		
	
	if($_GET['id']){
		$new_x_data['g_id']=$_GET['id'];
		$res_cinv_see=M('cinv_see')->where($new_x_data)->select();
		$res_cinv_times=M('cinv_times')->where($new_x_data)->select();
		$res_ad=M('goods_ad')->where($new_x_data)->select();
		$res_goods_link=M('goods_link')->where($new_x_data)->select();
		$res_goods_diy_name=M('goods_diy_name')->where($new_x_data)->select();
		$this->assign('new_x_data',array($res_cinv_see,$res_cinv_times,$res_ad,$res_goods_link));
	}
/***********************新增渲染数据（征信，广告，关联产品）*******************************/
/********************************渠道列表渲染*******************************/
		 $where['qudao_pro_id']=$_SESSION['user']['u_pro_id'];
		 $where['qudao_city_id']=$_SESSION['user']['u_city_id'];
		 $qudao = M('Qudao')->where($where)->group('qudao_type')->select();
		 $this->assign('qudao_list',$qudao);

/********************************渠道列表渲染*******************************/	
		$this->display();
	}
	/**
	 * 产品发布操作
	 * @DateTime:    [2018-03-08 10:02:21]
	 */
	public function issue(){
		$where_gx_id['gx_id'] = I('gx_id');
		$bm_goods=M('goods');
		$bm_gx=M('goods_gx');
		$goods = $bm_goods->where($where_gx_id)->select();
		if(count($goods)>=1){
			$i=0;
			foreach ($goods as $key => $value) {
				$where['id']=$value['id'];
				$data['is_show']=1;
				$gx_data['j_id']=1;
				$where_g['id']=I('gx_id');
				$bm_gx->where($where_g)->save($gx_data);
				$bm_goods->where($where)->save($data);
				unset($gx_data);
				unset($where);
				unset($data);
				$i++;
			}
			if(count($goods)==$i){
				$this->success('发布成功',U('Wxauthorise/manage_diqu_chanpin'),'3');
			}
			else{
				$this->success('发布成功商品'.$i.'个一共'.count($goods).'个产品',U('Wxauthorise/manage_diqu_chanpin'),'3');
			}
		}
		else{
			$this->success('没有可发布产品',U('Wxauthorise/manage_diqu_chanpin'),'3');
		}
	}
	/**
	 * 利用ajax处理银行选择产生对应渠道的名称，并列利用于add_chanpin
	 */
	public function ajax_add_chanpin(){
		 $where['qudao_pro_id']=$_SESSION['user']['u_pro_id'];
		 $where['qudao_city_id']=$_SESSION['user']['u_city_id'];
		 $where['qudao_type']=array('like','%'.$_POST['qudao_type'].'%');
		 $qudao = M('Qudao')->where($where)->select();
		 $this->ajaxReturn($qudao);
	}

	//基础信息添加
	public function Bm_zongadd(){
		$arr = $_POST;
		$bm_goods_foundation = M('goods_foundation');
		$bm_goods_gx = M('goods_gx');
/*************************修改处理***************************/
		foreach($arr as $v=>$k){
			if($v == 'simple'){
				continue;
			}
			$date['name'] = $k['chanpin_name'];
			$date['dtypename'] = $k['qudao_type'];//类型不做更新处理
			$date['qudaoname'] = $k['qudao_name'];
			$date['bzname'] = $k['chanpin_alt_name'];
			$bid = $k['id'];
			$save = $bm_goods_foundation->where('id = '.$bid)->save($date);	
		}
/*************************修改处理***************************/
		if($save){
			$this->success('添加成功',U('add_chanpin',array('dID'=>$arr['type'])));
		
		}
	}
	
	//产品添加2页面	//核心页面添加
	 public function add_adv_chanpin(){
		$id = $_GET['id'];				//产品ID
		$did = $_GET['did'];			//关系表ID
		$bm_lx = M('lx');			//利息表
		$bm_goods = M('goods');		//核心产品表
		$m = M('biaoqian');			//标签表
		$LX = $bm_lx->where('g_id='.$id)->select();
		$goods = $bm_goods->where('id = '.$id)->find();
		$goods['revenue'] = $goods['revenue']?fanhui($goods['revenue']):'';
		$goods['jinjian'] = $goods['jinjian']?fanhui($goods['jinjian']):'';
		$goods['lx'] = $goods['lx']?fanhui($goods['lx']):'';
		$goods['assessment'] = $goods['assessment']?fanhui($goods['assessment']):'';
		$goods['datami'] = $goods['datami']?fanhui($goods['datami']):'';
		$goods['area'] = $goods['area']?fanhui($goods['area']):'';
		$goods['especial'] =$goods['especial']? fanhui($goods['especial']):'';
		if($goods['cp_temp'] != ''){
				$dalid = $goods['daleiid'];
				$Bqian = $m->field('id,name')->where('f_id='.$dalid)->select();
				//各种标签
				$goods['daleiID'] = $dalid;
				$group = $bm_lx->where('g_id='.$id)->field('color_lx_id')-> select();
				foreach ($group as $key => $value) {
					$where0[$key]=$group[$key]['color_lx_id'];
				}
				if($where0){
					$where2['color_lx_id']=array('IN',implode(',',$where0));
				}
				$where1['color_goods_id']=$goods['color_goods_id'];
				//颜色新增渲染
				$lx_color=M('lx_color')->where($where2)->select();
				$goods_color=M('goods_color')->where($where1)->find();
				$this->assign('goods_color',$goods_color);		//商品渲染
				$this->assign('lx_color',$lx_color);			//利息喧嚷
				//利息渲染
				$this->assign('lx',$LX);

				/***********************************************************************/
				if($goods['cpclass']){
					$cpclass_where['md_id']=array('IN',$goods['cpclass']);
					$temp_goods['cpclass']=M('m_data')
									  ->where($cpclass_where)
									  ->field('bq_id')
									  ->group('bq_id')
									  ->select();
						$my_data=M('m_data');
					foreach ($temp_goods['cpclass'] as $key => $value) {
						  	$ar_cpclass['cpclass'][$key]['bm_id'] = $value['bq_id'];
						  	$ar_cpclass['cpclass'][$key]['my_data']=$my_data->where('bq_id='.$value['bq_id'])->where($cpclass_where)->field('md_id,m_group')->select();
						  }	 
				$this->assign('abc',json_encode($ar_cpclass));
				}
				/***********************************************************************/
				/*******************************征信************************************/
				if($_GET['id']){
					$new_x_data['g_id']=$_GET['id'];
					$res_cinv_see=M('cinv_see')->where($new_x_data)->select();
					$res_cinv_times=M('cinv_times')->where($new_x_data)->select();
					$res_ad=M('goods_ad')->where($new_x_data)->select();
					$res_goods_link=M('goods_link')->where($new_x_data)->select();
					$res_goods_diy_name=M('goods_diy_name')->where($new_x_data)->select();
					$showdata=array(json_encode($res_cinv_see),json_encode($res_cinv_times),json_encode($res_ad),$res_goods_link,json_encode($res_goods_diy_name));
					$this->assign('new_x_data',$showdata);
				}
				/*******************************征信************************************/

				//			选中标签渲染

				$this->assign('type',$Bqian);
		}
				$this->assign('goods',$goods);
		/*****************************银行昵称渲染*************************************/
		$qudao_where['u_pro_id']=$_SESSION['user']['u_pro_id'];
		$qudao_where['u_city_id']=$_SESSION['user']['u_city_id'];
		$qudao_list=M('qudao')->where($qudao_where)->select();
		$this->assign('qudao_list',$qudao_list);
		/*****************************银行昵称渲染*************************************/

		
		$bm_biaoqian = $m->where("type = 8")->select();		//大类标签查询
		$type1 = $m->where('type = 1')->select();			//收入标签查询
		$type2 = $m->where('type = 2')->select();			//进件标签查询
		$type3 = $m->where('type = 3')->select();			//利息额度标签查询
		$type4 = $m->where('type = 4')->select();			//考核标签查询
		$type5 = $m->where('type = 5')->select();			//时间维度标签查询
		$type6 = $m->where('type = 6')->select();			//地区维度标签查询
		$type7 = $m->where('type = 7')->select();			//特殊标签查询
		$this->assign('type1',$type1);
		$this->assign('type2',$type2);
		$this->assign('type3',$type3);
		$this->assign('type4',$type4);
		$this->assign('type5',$type5);
		$this->assign('type6',$type6);
		$this->assign('type7',$type7);
		$this->assign('bm',$bm_biaoqian);
		$this->assign('info',$id);
		$this->assign('did',$did);
		$this->display();
	} 
	
	//ajax添加核心信息列表
	public function cp_add(){
		$id1 = $_POST['id'];
		$user = M('goods');				//商品核心信息表
		$bm_goods_gx = M('goods_gx');	//关联表
		$arr['l_id'] = '0';
		$arr['gx_id'] = $id1;
		$ad_id=$_POST['ab_id'];
		if($ad_id){
			$sb_data=M('goods')->where("id=".$ad_id)->find();
			foreach ($sb_data as $key => $value) {
				if($key!='id'&&$key!='cp_temp'&&$key!='cpclass'&&$key!='daleiid'&&$key!='l_id'&&$key!='gx_id'){
					$arr[$key]=$value;
				}
			}
		}
		$id = $user->add($arr);
		if($id){
		   $this->ajaxReturn($id);
		}
	}
	/**
	 * 删除核心信息
	 * @return [type] [description]
	 * @DateTime:    [2018-03-26 12:30:22]
	 * 事务处理
	 */
	public function del_cp(){
		 if(IS_POST&&IS_AJAX){
		 		$del_arr=$_POST['good_id'];
		 		/**
		 		 * 商品关联数据
		 		 * 商品 $del_arr; 
		 		 * 广告 g_id
		 		 * 征信 查看g_id
		 		 * 征信 次数g_id
		 		 * 利息g_id
		 		 * 利息颜色 利息表对应color_lx_id
		 		 * 商品颜色 商品color_goods_id
		 		 * diy表单数据 商品cpclass字符串转数组
		 		 * 关联产品数据g_id
		 		 * 
		 		 */
		 		/**************************************/
		 		$where_g_id['g_id']=array('IN',$del_arr);
				$where_goods_id['id']=array('IN',$del_arr);
		 		$table_goods=M('goods');
		 		$table_lx=M('lx');
		 		$table_goods_ad=M('goods_ad');
		 		$table_cinv_see=M('cinv_see');
		 		$table_cinv_times=M('cinv_times');
		 		$table_goods_color=M('goods_color');
		 		$table_lx_color=M('lx_color');
		 		$table_m_data=M('m_data');
		 		$table_goods_link=M('goods_link');
		 		$cpclass_color_goods_id_arr=$table_goods->where($where_goods_id)->field('cpclass,color_goods_id')->select();
		 		$lx_arr=$table_lx->where($where_g_id)->select();
		 		foreach ($lx_arr as $key_lx => $value_lx) {
		 			$where_lx.=$value_lx['color_lx_id'].',';
		 		}
		 		foreach ($cpclass_color_goods_id_arr as $key_cr => $value_cr) {
		 			$where_m_data.=$value_cr['cpclass'].',';
		 			$where_goods_color.=$value_cr['color_goods_id'].',';
		 		}
		 		$table_goods->startTrans();
		 		$table_lx->startTrans();
		 		$table_goods_ad->startTrans();
		 		$table_cinv_see->startTrans();
		 		$table_cinv_times->startTrans();
		 		$table_goods_color->startTrans();
		 		$table_lx_color->startTrans();
		 		$table_m_data->startTrans();
		 		$table_goods_link->startTrans();
		 		$temp_goods=$table_goods->delete($del_arr);
		 		$temp_lx=$table_lx->where($where_g_id)->delete();
		 		$temp_goods_ad=$table_goods_ad->where($where_g_id)->delete();
		 		$temp_cinv_see=$table_cinv_see->where($where_g_id)->delete();
		 		$temp_cinv_times=$table_cinv_times->where($where_g_id)->delete();
		 		$temp_goods_color=$table_goods_color->delete($where_goods_color);
		 		$temp_lx_color=$table_lx_color->delete($where_lx);
		 		$temp_m_data=$table_m_data->delete($where_m_data);
		 		$temp_goods_link=$table_goods_link->where($where_g_id)->delete();
		 		if($temp_goods>=0&&
		 		   $temp_lx>=0&&
		 		   $temp_goods_ad>=0&&
		 		   $temp_cinv_see>=0&&
		 		   $temp_cinv_times>=0&&
		 		   $temp_goods_color>=0&&
		 		   $temp_lx_color>=0&&
		 		   $temp_m_data>=0&&
		 		   $temp_goods_link>=0){
			 		$table_goods->commit();
			 		$table_lx->commit();
			 		$table_goods_ad->commit();
			 		$table_cinv_see->commit();
			 		$table_cinv_times->commit();
			 		$table_goods_color->commit();
			 		$table_lx_color->commit();
			 		$table_m_data->commit();
			 		$table_goods_link->commit();
		 			$msg['code']=1;
		 			$msg['message']='删除成功';
		 			$msg['data']="$temp_goods,$temp_lx,$temp_goods_ad,$temp_cinv_see,$temp_cinv_times,$temp_goods_color,$temp_lx_color,$temp_m_data,$temp_goods_link";
		 		}
		 		else{
			 		$table_goods->rollback();
			 		$table_lx->rollback();
			 		$table_goods_ad->rollback();
			 		$table_cinv_see->rollback();
			 		$table_cinv_times->rollback();
			 		$table_goods_color->rollback();
			 		$table_lx_color->rollback();
			 		$table_m_data->rollback();
			 		$table_goods_link->rollback();
		 			$msg['code']=2;
		 			$msg['message']='删除失败，数据错误';
		 			$msg['data']="$temp_goods,$temp_lx,$temp_goods_ad,$temp_cinv_see,$temp_cinv_times,$temp_goods_color,$temp_lx_color,$temp_m_data,$temp_goods_link";
		 		}
		 }
		 else{
		 	$msg['code']=3;
		 	$msg['message']='传输错误';
		 }
		 $this->ajaxReturn($msg);
	}
	/**
	 * ajax 添加颜色
	 */
	public function ajax_color(){
		header("Content-Type: text/html; charset=utf-8");

		$arr = $_POST;
		//return json_encode($_POST);
		$arr1=$arr['data'];
		//dump($arr1);die;
		$bm_lx = M('lx_color');   	//	利息分布表
		$bm_goods = M('goods_color');   	//	商品表
		$sanwei = $arr1[40];
		//dump($sanwei);die;
		//添加多条利息
	//	$this->ajaxReturn($_POST);
		foreach($sanwei as $v=>$k){
			$data_lx['min_lx'] = $sanwei[$v][0]['value'];
			$data_lx['max_lx'] = $sanwei[$v][1]['value'];
			$data_lx['min_ed'] = $sanwei[$v][2]['value'];
			$data_lx['max_ed'] = $sanwei[$v][3]['value'];
			$data_lx['repayments'] = $sanwei[$v][4]['value'];
			$data_lx['installment_fq'] = $sanwei[$v][5]['value'];
			$data_lx['handling'] = $sanwei[$v][6]['value'];
			$data_lx['collection'] = $sanwei[$v][7]['value'];
			$data_lx['return'] = $sanwei[$v][8]['value'];
			$data_lx['fangkuan_time'] = $sanwei[$v][9]['value'];
			$data_lx['lx_remark'] = $sanwei[$v][10]['value'];
		//	$this->ajaxReturn($data_lx);
			$res[$v]=$bm_lx->add($data_lx);
		}
		$res_data['color_lx_id']=$res;
	//	$this->ajaxReturn($res_data);
		$data['general'] = $arr1[3]['value'];								//一般详情要求
		$data['jjdetail'] = $arr1[4]['value'];							//进件详情要求
		$data['letter'] = $arr1[5]['value'];							//征信详情要求
		$data['debt'] = $arr1[6]['value'];									//负债详情要求
		$data['revenue_yq'] = $arr1[7]['value'];							//收入详情要求
		/***************************** 各大要求添加 *************************************************/
		$data['zonggn'] = $arr1[8]['value'];							    //总攻略
		$data['unit_type'] = $arr1[9]['value'];							//电核单位
		$data['danwei_zidingyi'] = $arr1[10]['value'];							//单位自定义

		$data['spouse_type'] = $arr1[11]['value'];							//电核配偶
		$data['peiou_zidingyi'] = $arr1[12]['value'];							//电核配偶
		$data['zhixi_type'] = $arr1[13]['value'];							//电核直系
		$data['zhixi_zhidingyi'] = $arr1[14]['value'];							//电核自定义

		$data['relatives_type'] = $arr1[15]['value'];						//电核亲属
		$data['qingsu_zidingyi']=$arr1[16]['value'];					//亲属自定义
		$data['colleagues_type'] = $arr1[17]['value'];					//电核同事
		$data['tongshi_zidingyi'] = $arr1[18]['value'];					//同事自定义
		$data['friend_type'] = $arr1[19]['value'];						//电核朋友
		$data['pengyou_zidingyi'] = $arr1[20]['value'];						//朋友自定义
		$data['data_type'] = $arr1[21]['value'];							//查大数据
		$data['shield'] = $arr1[22]['value'];						//查同盾
		$data['folk'] = $arr1[23]['value'];							//查民间
		$data['liushui'] = $arr1[24]['value'];							//查流水
		$data['Letterzhengxin'] = $arr1[25]['value'];					//查征信显示
		$data['zhengxin_xianshi'] = $arr1[26]['value'];					//查征信显示
		$data['Lendingfangshi'] = $arr1[27]['value'];			//放款方式
		$data['inspection_type'] = $arr1[28]['value'];		//上门考察
		$data['zhunruyaoqiu'] = $arr1[29]['value'];						//准入要求
		$data['age_min'] = $arr1[30]['value'];				//进件最低年龄
		$data['age_max'] = $arr1[31]['value'];				//进件最高年龄
		$data['shourshenfen'] = $arr1[32]['value'];			//收入身份
		$data['jinjian_wuye'] = $arr1[33]['value'];					//无业身份
		$data['gender'] = $arr1[34]['value'];						//性别
		$data['xinyongshenf'] = $arr1[35]['value'];				//信用身份
		$data['yihun'] = $arr1[36]['value'];						//已婚双签
		$data['jinjianrequired'] = $arr1[37]['value'];				//进件所需资料
		$data['forbade'] = $arr1[38]['value'];				//信用身份
		$data['kaocha'] = $arr1[39]['value'];								//考察
		$color_goods_id = M('goods_color')->data($data)->add();
		$res_data['color_goods_id']=$color_goods_id;
		$this->ajaxReturn($res_data);
	}
	
	/**
	 * ajax添加标签
	 */
	public function bq_ajax(){
				$m = M('biaoqian');
				$arr['name'] =  $_GET['mainName'];
				$arr['type'] = $_GET['type'];
				$arr['biemin'] = $_GET['altName'];
				$arr['xiangqign'] = $_GET['summary'];
				if($_GET['dalei']&&$arr['type']==1){
					$arr['f_id'] = $_GET['dalei'];
				}
				$id = $m->add($arr);
				if($id){
				    $this->ajaxReturn($id);
				}
	}
	//核心产品添加页面
	public function chanpin_add(){
		header("Content-Type: text/html; charset=utf-8");
		$arr1 = $_POST;
		$bm_lx = M('lx');   	//	利息分布表
		$bm_goods = M('goods');   	//	商品表
		$bm_goods_gx = M('goods_gx');
		$sanwei = $arr1['sanwei'];
		foreach ($sanwei as $key => $value) {
					$lx_arr[$key]['id']=$value['id'];
					$lx_arr[$key]['min_lx'] = $value['lixi_min'];
					$lx_arr[$key]['max_lx'] = $value['lixi_max'];
					$lx_arr[$key]['min_ed'] = $value['edu_min'];
					$lx_arr[$key]['max_ed'] = $value['edu_max'];
					$lx_arr[$key]['repayments'] = $value['huankuan'];
					$lx_arr[$key]['installment_fq'] = $value['fenqi_max'];
					$lx_arr[$key]['handling'] = $value['fangkuan_shouxufei'];
					$lx_arr[$key]['collection'] = $value['daishou'];
					$lx_arr[$key]['return'] = $value['fandian'];
					$lx_arr[$key]['lx_remark'] = $value['du_zhuxi'];
					$lx_arr[$key]['fangkuan_time'] = $value['fangkuan_time'];
					$lx_arr[$key]['g_id'] = $arr1['id'];
					if(isset($arr1['color_lx_id']['lixi'.$key])){
						$lx_arr[$key]['color_lx_id'] =$arr1['color_lx_id']['lixi'.$key];		//颜色关联
					}
					$where_ix['id']=$lx_arr[$key]['id'];
					$bm_lx->where($where_ix)->save($lx_arr[$key]);
		}

//	die;
		$date['daleiID'] = $arr1['dalei'];								//大类ID
		$date['litter_name'] = $arr1['litter_name'];					//产品小名
		$date['cpclass'] = implode(',',$arr1['check_xiaolei']);			//小类标签ID(修改逻辑)  有多个
		$date['cp_temp']=implode(',',$arr1['check']);
		$date['revenue'] = implode(',',$arr1['check_shouru']);			//收入标签ID  有多个
		$date['jinjian'] = implode(',',$arr1['check_jinjian']);			//进件标签ID  有多个
		$date['lx'] = implode(',',$arr1['check_lixiedu']);				//利息额度ID  有多个
		$date['assessment'] = implode(',',$arr1['check_kaohe']);		//考核标签ID  有多个
		$date['datami'] = implode(',',$arr1['check_shijian']);			//时间维度ID  有多个
		$date['area'] = implode(',',$arr1['check_diqu']);				//地区维度ID  有多个
		$date['especial'] = implode(',',$arr1['check_teshu']);			//特殊标签ID  有多个
		$date['general'] = $arr1['yiban'];								//一般详情要求
		$date['jjdetail'] = $arr1['jinjian'];							//进件详情要求
		$date['letter'] = $arr1['zhengxin'];							//征信详情要求
		$date['debt'] = $arr1['fuzai'];									//负债详情要求
		$date['revenue_yq'] = $arr1['shouru'];							//收入详情要求
		/***************************** 各大要求添加 *************************************************/
		$date['zhengxin_xianshi']=$arr1['zhengxin_xianshi'];			//上征信
		$date['liushui']=$arr1['liushui'];								//查流水单位
		$date['zonggn'] = $arr1['zonggn'];							    //总攻略
		$date['unit_type'] = $arr1['danwei'];							//电核单位
		$date['spouse_type'] = $arr1['peiou'];							//电核配偶
		$date['zhixi_type'] = $arr1['zhixi'];							//电核直系
		$date['relatives_type'] = $arr1['qingsu'];						//电核亲属
		$date['colleagues_type'] = $arr1['tongshi'];					//电核同事
		$date['friend_type'] = $arr1['pengyou'];						//电核朋友
		$date['data_type'] = $arr1['dashuju'];							//查大数据
		$date['shield_type'] = $arr1['tongdun'];						//查同盾
		$date['folk_type'] = $arr1['minjian'];							//查民间
		$date['Letterzhengxin'] = $arr1['chazhengxin'];					//查征信显示
		$date['Lendingfangshi'] = $arr1['fangkuan_fangshi_se'];			//放款方式
		$date['inspection_type'] = implode(',',	$arr1['shangmen']);		//上门考察
		$date['kaocha'] = $arr1['kaocha'];								//考察
		$date['zhunruyaoqiu'] = $arr1['zhunru'];						//准入要求
		$date['age_min'] = $arr1['jinjian_nianling_min'];				//进件最低年龄
		$date['age_max'] = $arr1['jinjian_nianling_max'];				//进件最高年龄
		$date['shourshenfen'] = $arr1['jinjian_shourushenfen'];			//收入身份
		$date['jinjian_wuye'] = $arr1['jinjian_wuye'];					//无业身份
		$date['gender'] = $arr1['jinjian_xingbie'];						//性别
		$date['xinyongshenf'] = $arr1['jinjian_xinyong'];				//信用身份
		$date['yihun'] = $arr1['jinjian_yihun'];						//已婚双签
		if($arr1['color_goods_id']){
		$date['color_goods_id'] = $arr1['color_goods_id'];				//添加颜色关联表id
		}
		$date['jinjianrequired'] = $arr1['jinjian_ziliao'];				//进件所需资料
		$date['forbade'] = implode(',',$arr1['jinzhi']);				//禁止
		$date['u_id'] = $_SESSION['user']['u_id'];				//省

		$id = $arr1['id'];
		$did = $arr1['did'];

		$goods_orders = $bm_goods->where("id = $id")->save($date);
		 if($goods_orders){
			$shi['shifou'] = 2;
			$shi['timeda'] = date("Y-m-d H:i:s");
			$bm_goods_gx->where("id = $did")->save($shi);	//修改关联表状态
			$this->success('修改成功',U('add_chanpin',array('dID'=>$did)));
			
		}else{
			$this->error('修改失败');
		}
	}
	public function nav_1(){
		$this->display('diqu_nav');
	}
	/**
	 * del_lx
	 * 删除lx
	 */
	public function del_lx(){
		if($_POST){
			$res['code']=200;
			$res['message']='';
			$ro1=M('lx')->where($_POST)->find();
			$ro=M('lx')->where($_POST)->delete();
			if($ro){
				//M('')->where('')->save($data);
			}
			else{
				$res['code']=202;
				$res['message']='删除错误';
			}
			$this->ajaxReturn($res);
		}
		else{
			$this->display("<h1>404</h1>");
		}
	}
	//基础信息。核心信息/关联函数
	public function cj_xinxi(){
		$id = $_POST['id'];
		//echo $id;die;
		$bm_goods_foundation = M('goods_foundation');			//基础信息表
		$bm_goods_gx = M('goods_gx');							//关联表
		if($id == ''){
			$name['shifou'] = 1;
			$list = $bm_goods_gx->add($name);
			if($list){
				$arr['gx_id'] = $list;
				$arr['u_id']=session('user.u_id');
				$bm_goods = $bm_goods_foundation->add($arr);
				if($bm_goods){
					$str = $list.'|'.$bm_goods;
					$this->ajaxReturn($str);
				}
			}
		}else{
			$bool = $bm_goods_gx->where('id='.$id)->find();
			if($bool){
				$arr['gx_id'] = $id;
				$arr['u_id']=session('user.u_id');
				$bm_goods = $bm_goods_foundation->add($arr);
				if($bm_goods){
					$str = $id.'|'.$bm_goods;
					$this->ajaxReturn($str);
				}
			}
		}
	}
	/**
	 * 删除基础信息
	 * @return [type] [description]
	 */
	public function del_cj_xinxi(){
		 if(IS_POST&&IS_AJAX){
		 		$del_arr=$_POST['jc_id'];
		 		$res=M('goods_foundation')->delete($del_arr);
		 		if($res){
		 			$msg['code']=1;
		 			$msg['message']='删除成功';
		 			$msg['data']=$res;
		 		}
		 		else{
		 			$msg['code']=2;
		 			$msg['message']='删除失败，数据错误';
		 			$msg['data']=$res;
		 		}
		 }
		 else{
		 	$msg['code']=3;
		 	$msg['message']='传输错误';
		 }
		 $this->ajaxReturn($msg);
	}

	public function daleiajax(){
		$id = $_GET['id'];
		//echo $id;die;
		$m = M('biaoqian');
		$bm_biaoqian = $m->where("f_id = $id")->select();
		$this->ajaxReturn($bm_biaoqian,'JSON');
	}
/************************ajax添加小类方法***********************/
	public function suoyoubiaoqian(){
		$m = M('biaoqian');
		$arr['name'] =  $_GET['mainName'];
		$arr['type'] = $_GET['type'];
		$arr['biemin'] = $_GET['altName'];
		$arr['xiangqign'] = $_GET['summary'];
		$arr['f_id'] = $_GET['dalei'];
		$id = $m->add($arr);
		if($id){
			$this->ajaxReturn($id);
		}
	}
	
	/**
	 * ajax添加小类的属结构
	 * @return [type] [description]
	 */
	public function sm_ajax(){
		//$result=$_POST;
		$result=D('Wxauthorise')->sm_ajax();
		$resu['code']=1;
		$resu['message']=$result;
		$this->ajaxReturn($resu);
	}



	/**
	 * 返回小类结构属性
	 */
	public function biaoqian_ajax(){
		

		$res=D('Wxauthorise')->get_ajax();
		$this->ajaxReturn($res);

	}
	/**
	 * 数据id换取数据
	 */
	public  function re_m_data(){
		if(IS_AJAX&&$_POST['md_id']){
			$red=M('m_data')->where($_POST)->find();
			if($red){
				$msg['code']='1';
				$msg['message']='请求成功';
				$msg['data']=$red;
			}
			else{
				$msg['code']='3';
				$msg['message']='数据为空';
				
			}
		}
		else{
			$msg['code']='2';
			$msg['message']='非ajax请求';
		}
		$this->ajaxReturn($msg);
	}
	/**
	 * 添加小类数据
	 */
	public  function add_xiaolei(){
		if(IS_AJAX){
			foreach ($_POST['formData'] as $key => $value) {
				if(is_array($value)){
					$res[$key]=M('m_data')->data($_POST['formData'][$key])->add();
				}

			}
			if($res){
				$msg['code']=1;
				$msg['message']='添加成功';
				$msg['data']=$res;
			}
			else{
				$msg['code']=2;
				$msg['message']='添加数据失败';
			}
		}
		else{
			$msg['code']=3;
			$msg['message']='非ajax请求';
		}
		$this->ajaxReturn($msg);
	}
	/**
	 * ajax动态添加lx
	 * @return [type] [description]
	 */
	public function ajax_add_lx(){
		$m = M('lx');
		$arr['g_id'] = $_POST['g_id'];
		$id = $m->add($arr);
		if($id){
			$up = $m->where('id='.$id)->save($arr);	
			if($up){
				$msg['code']=1;
				$msg['message']='请求成功';
				$msg['data']=$id;

			}
			else{
				//$m->where('id='.$id)->delete();
				$msg['code']=1;
				$msg['message']='修改发生错误';
				$msg['data']=$id;
			}
		}
		else{
			$msg['code']=3;
			$msg['message']='添加失败';
		}
		$this->ajaxReturn($msg);
	}
	/********************ajax添加，删除征信查询********************************/
	/**
	 * ajax脱离处理征信次数
	 * @return [type] [description]
	 */
	public function ajax_add_zx_times(){
		if(IS_POST && IS_AJAX){
			$arr=$_POST;
			$res=M('cinv_times')->data($arr)->add();
			if($res){
				$msg['code']=1;
				$msg['message']='添加成功';
				$msg['cinv_times_id']=$res;
			}
			else{
				$msg['code']=2;
				$msg['message']='添加失败';
			}

		}
		else{
			$msg['code']=3;
			$msg['message']="请求方式错误"; 
		}
		$this->ajaxReturn($msg);
	}
	public function ajax_del_zx_times(){
		if(IS_POST && IS_AJAX){
			$arr=$_POST['cinv_times_id'];
			$res=M('cinv_times')->delete($arr);
			if($res){
				$msg['code']=1;
				$msg['message']='删除成功';
			}
			else{
				$msg['code']=2;
				$msg['message']='删除失败';
			}

		}
		else{
			$msg['code']=3;
			$msg['message']="请求方式错误"; 
		}
		$this->ajaxReturn($msg);
	}
	/**
	 * 更新数据
	 * @return [type] [description]
	 */
	public function ajax_update_zx_times(){
		if(IS_POST && IS_AJAX){
			$arr=$_POST['data'];
			
			//$k=0;
			for ($i=0; $i < count($arr); $i++) { 
				$res=M('cinv_times')->save($arr[$i]);
			}
			if($res){
				$msg['code']=1;
				$msg['message']='更新成功';
			}
			else{
				$msg['code']=2;
				$msg['message']='更新失败';
				$msg['data']=$_POST;
			}

		}
		else{
			$msg['code']=3;
			$msg['message']="请求方式错误"; 
		}
		$this->ajaxReturn($msg);
	}

	/**
	 * ajax删除see
	 */
	public function ajax_add_zx_see(){
		if(IS_POST && IS_AJAX){
			$arr=$_POST;
			$res=M('cinv_see')->data($arr)->add();
			if($res){
				$msg['code']=1;
				$msg['message']='添加成功';
				$msg['cinv_see_id']=$res;
			}
			else{
				$msg['code']=2;
				$msg['message']='添加失败';
			}

		}
		else{
			$msg['code']=3;
			$msg['message']="请求方式错误"; 
		}
		$this->ajaxReturn($msg);
	}
		public function ajax_del_zx_see(){
			if(IS_POST && IS_AJAX){
				$arr=$_POST['cinv_see_id'];
				$res=M('cinv_see')->delete($arr);
				if($res){
					$msg['code']=1;
					$msg['message']='删除成功';
				}
				else{
					$msg['code']=2;
					$msg['message']='删除失败';
				}

			}
			else{
				$msg['code']=3;
				$msg['message']="请求方式错误"; 
			}
			$this->ajaxReturn($msg);
		}
		/**
		 * 更新数据
		 * @return [type] [description]
		 */
		public function ajax_update_zx_sees(){
			if(IS_POST && IS_AJAX){
				$arr=$_POST['data'];
				for ($i=0; $i < count($arr); $i++) { 
					$res=M('cinv_see')->save($arr[$i]);
				}
				if($res){
					$msg['code']=1;
					$msg['message']='修改成功';
					$msg['data']=$res;
				}
				else{
					$msg['code']=2;
					$msg['message']='修改失败';
					$msg['data']=$res;
				}

			}
			else{
				$msg['code']=3;
				$msg['message']="请求方式错误"; 
			}
			$this->ajaxReturn($msg);
		}

	/********************ajax添加，删除征信查询********************************/


	/************************脱离表单处理商品关联******************************/
					/**********产品筛选关联********/

		/**
		 * 大类渲染数据
		 * @return [type] [description]
		 */
		public function ajax_get_dalei(){
			if(IS_AJAX){
				$where['type']=8;
				$res=M('biaoqian')->where($where)->field('id,name,biemin,xiangqign')->select();
				if($res){
					$msg['code']=1;
					$msg['message']='返回数据';
					$msg['data']=$res;
				}
				else{
					$msg['code']=2;
					$msg['message']='没有指定数据';
				}
			}	
			else{
					$msg['code']=3;
					$msg['message']='请用ajax请求';
			}
			$this->ajaxReturn($msg);
		}
		/**
		 * ajax获取关联小类
		 * @return [type] [description]
		 */
		public function ajax_get_cpclass(){
			if(IS_AJAX){
				$where['f_id']=$_POST['f_id'];
				$res=M('biaoqian')->where($where)->field('id,name,biemin,xiangqign')->select();
				if($res){
					$msg['code']=1;
					$msg['message']='返回数据';
					$msg['data']=$res;
				}
				else{
					$msg['code']=2;
					$msg['message']='没有指定数据';
				}
			}	
			else{
					$msg['code']=3;
					$msg['message']='请用ajax请求';
			}
			$this->ajaxReturn($msg);
		}
		/**
		 * 获取垃圾名(小名)
		 * @return [type] [description]
		 */
		public function ajax_get_litter_name(){
			if(IS_AJAX){
				$where['cp_temp']=array('LIKE','%'.$_POST['cp_temp'].'%');
				$res=M('goods')->where($where)->field('id,cp_temp,litter_name,u_id')->select();
				if($res){
					$msg['code']=1;
					$msg['message']='返回数据';
					$msg['data']=$res;
				}
				else{
					$msg['code']=2;
					$msg['message']='没有指定数据';
				}
			}	
			else{
					$msg['code']=3;
					$msg['message']='请用ajax请求';
			}
			$this->ajaxReturn($msg);
		}
					/**********产品筛选关联********/


		public function ajax_add_goods_links(){
			if(IS_POST && IS_AJAX){
				$arr=$_POST;
				$arr['time']=date("Y年m月d日 h:i:s");
				$arr['u_id']=session('user.u_id');
				$res=M('goods_link')->data($arr)->add();
				if($res){
					$msg['code']=1;
					$msg['message']='添加成功';
					$msg['goods_link_id']=$res;
				}
				else{
					$msg['code']=2;
					$msg['message']='添加失败';
				}

			}
			else{
				$msg['code']=3;
				$msg['message']="请求方式错误"; 
			}
			$this->ajaxReturn($msg);
		}
		public function ajax_del_goods_links(){
			if(IS_POST && IS_AJAX){
				$arr=$_POST['goods_link_id'];
				$res=M('goods_link')->delete($arr);
				if($res){
					$msg['code']=1;
					$msg['message']='删除成功';
				}
				else{
					$msg['code']=2;
					$msg['message']='删除失败';
				}

			}
			else{
				$msg['code']=3;
				$msg['message']="请求方式错误"; 
			}
			$this->ajaxReturn($msg);
		}
		/**
		 * 更新数据
		 * @return [type] [description]
		 */
		public function ajax_update_goods_links(){
			if(IS_POST && IS_AJAX){
				$arr=$_POST['data'];
				for ($i=0; $i < count($arr); $i++) { 
				$new_arr=$arr[$i];
				$new_arr['time']=date("Y年m月d日 h:i:s");
				//$arr['u_id']=session('user.u_id');
				$res[$i]=M('goods_link')->save($new_arr);
				}
				if($res){
					$msg['code']=1;
					$msg['message']='修改成功';
					$msg['data']=$res;
				}
				else{
					$msg['code']=2;
					$msg['message']='修改失败';
					$msg['data']=$res;
				}

			}
			else{
				$msg['code']=3;
				$msg['message']="请求方式错误"; 
			}
			$this->ajaxReturn($msg);
		}

	
	/**************************脱离表单处理广告******************************/
	/**
	 * 图片ajax上传
	 * @return [type] [description]
	 */
	public function ajax_ad_img(){
		$res=D('User')->upload_img('ad');
		$this->ajaxReturn($res);
	
	}

	public function ajax_add_goods_ad(){
		if(IS_POST && IS_AJAX){
			$arr=$_POST;
			$arr['time']=date("Y年m月d日 h:i:s");
			$arr['u_id']=session('user.u_id');
			$res=M('goods_ad')->data($arr)->add();
			if($res){
				$msg['code']=1;
				$msg['message']='添加成功';
				$msg['goods_ad_id']=$res;
			}
			else{
				$msg['code']=2;
				$msg['message']='添加失败';
				$msg['data']=$res;
			}

		}
		else{
			$msg['code']=3;
			$msg['message']="请求方式错误"; 
		}
		$this->ajaxReturn($msg);
	}
	public function ajax_del_goods_ad(){
		if(IS_POST && IS_AJAX){
			$arr=$_POST['goods_ad_id'];
			$res=M('goods_ad')->delete($arr);
			if($res){
				$msg['code']=1;
				$msg['message']='删除成功';
				$msg['data']=$res;
			}
			else{
				$msg['code']=2;
				$msg['message']='删除失败';
				$msg['data']=$res;
			}

		}
		else{
			$msg['code']=3;
			$msg['message']="请求方式错误"; 
		}
		$this->ajaxReturn($msg);
	}
	/**
	 * 更新数据
	 * @return [type] [description]
	 */
	public function ajax_update_goods_ad(){
		if(IS_POST && IS_AJAX){
				$new_arr=$_POST;
				$new_arr['time']=date("Y年m月d日 h:i:s");
				$res=M('goods_ad')->save($new_arr);
			if($res){
				$msg['code']=1;
				$msg['message']='修改成功';
				$msg['data']=$res;
			}
			else{
				$msg['code']=2;
				$msg['message']='修改失败';
				$msg['data']=$res;

			}

		}
		else{
			$msg['code']=3;
			$msg['message']="请求方式错误"; 
		}
		$this->ajaxReturn($msg);
	}


	/**************************脱离表单处理广告******************************/
	/************************新增推荐理由******************************/
	public function ajax_add_goods_diy_name(){
		if(IS_POST && IS_AJAX){
			$arr=$_POST;
			$res=M('goods_diy_name')->data($arr)->add();
			if($res){
				$msg['code']=1;
				$msg['message']='添加成功';
				$msg['goods_diy_name_id']=$res;
			}
			else{
				$msg['code']=2;
				$msg['message']='添加失败';
				$msg['data']=$res;
			}

		}
		else{
			$msg['code']=3;
			$msg['message']="请求方式错误"; 
		}
		$this->ajaxReturn($msg);
	}
	public function ajax_del_goods_diy_name(){
		if(IS_POST && IS_AJAX){
			$arr=$_POST['goods_diy_name_id'];
			$res=M('goods_diy_name')->delete($arr);
			if($res){
				$msg['code']=1;
				$msg['message']='删除成功';
				$msg['data']=$res;
			}
			else{
				$msg['code']=2;
				$msg['message']='删除失败';
				$msg['data']=$res;
			}

		}
		else{
			$msg['code']=3;
			$msg['message']="请求方式错误"; 
		}
		$this->ajaxReturn($msg);
	}
	/**
	 * 更新数据
	 * @return [type] [description]
	 */
	public function ajax_update_goods_diy_name(){
		if(IS_POST && IS_AJAX){
			$arr=$_POST;
			$res=M('goods_diy_name')->save($arr);

			if($res){
				$msg['code']=1;
				$msg['message']='修改成功';
				$msg['data']=$res;
			}
			else{
				$msg['code']=2;
				$msg['message']='修改失败';
				$msg['data']=$res;

			}

		}
		else{
			$msg['code']=3;
			$msg['message']="请求方式错误"; 
		}
		$this->ajaxReturn($msg);
	}
	/************************新增推荐理由******************************/
	/**
	 * 标签删除如果使用了不可以删除
	 * @DateTime:    [2018-03-15 13:57:44]
	 */
	public function ajax_del_biaoqian(){
		if(true){
			$biaoqian_arr_id=array('cp_temp','revenue','jinjian','lx','assessment','datami','area','especial');
			$name=$_POST['biaoqian_type']?$_POST['biaoqian_type']:$_GET['biaoqian_type'];
			$where_biaoqian['id']=$_POST['biaoqian_id']?$_POST['biaoqian_id']:$_GET['biaoqian_id'];
			$res=M('biaoqian')->where($where_biaoqian)->find();
			if($res){
			  	if(in_array($name,$biaoqian_arr_id)){
					$biaoqian_id[$name]=array('LIKE','%'.$where_biaoqian['id'].'%');
					$goods_data=M('goods')->where($biaoqian_id)->field('id,litter_name')->select();
					if($goods_data){
						$temp_arr=array();
						foreach ($goods_data as $key => $value) {
							$biaoqian_arr_temp['id']=$value['id'];
							$biaoqian_arr_temp['litter_name']=$value['litter_name'];
							array_push($temp_arr,$biaoqian_arr_temp);
						}
						$msg['code']=1;
						$msg['message']='当前存在商品有';
						$msg['data']=$temp_arr;
					}	
					else{
						$bqd=M('biaoqian')->where($where_biaoqian)->delete();
						if($bqd){
							$msg['code']=2;
							$msg['message']='删除成功';
						}
						else{
							$msg['code']=3;
							$msg['message']='删除失败';
						}
					}
			 	 }
			  else{
				$msg['code']=6;
				$msg['message']='便签类型不符合规范';
			  }
			}
			else{
				$msg['code']=4;
				$msg['message']='标签不存在';
			}
		}
		else{
			$msg['code']=5;
			$msg['message']='传输格式错误';
		}
		$this->ajaxReturn($msg);
	}
}
	



































































